package borge.web.teamspirit.client.page.shared.widgets;

import borge.web.teamspirit.client.TeamSpirit;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler;
import borge.web.teamspirit.client.interfaces.WidgetEventHandler.WidgetEventType;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class LoggedInWidget extends BaseWidget implements ClickHandler{
	
	private VerticalPanel iPanel;
	private Label iLabel;
	private Button iButton;
	
	public LoggedInWidget(WidgetEventHandler aWeh, String aUsername){
		
		super(aWeh);
		
		iLabel = new Label();
		iLabel.setText(TeamSpirit.getConstants().logged_in_as() + ": " + aUsername);
		
		iButton = new Button();
		iButton.setText(TeamSpirit.getConstants().logout());
		iButton.addClickHandler(this);
		
		iPanel = new VerticalPanel();
		iPanel.add(iLabel);
		iPanel.add(iButton);
		
		initWidget(iPanel);
	}
	
	public void setUsername(String aUsername){
		iLabel.setText(TeamSpirit.getConstants().logged_in_as() + ": " + aUsername);
	}
	
	public void onClick(ClickEvent aEvent) {
		
		postEvent(WidgetEventType.LOGGED_OUT);
		
	}

}
